<template>
  <div id="head">
    <div>
      <div>
        <h1><router-link to="/index" style="color: white">畅 游 山 水</router-link></h1>
        <h3>辽宁 · 本溪</h3>
      </div>
      <div class="nav">
        <ul>
          <li>
            <router-link to="/play">走进本溪</router-link>
          </li>
          <li>
            <router-link to="/museum">特色产品</router-link>
          </li>
          <li>
            <router-link to="/tikInfo">线上服务</router-link>
          </li>
          <li>
            <router-link to="/trip">旅游推荐</router-link>
          </li>
          <li>
            <router-link to="/bussiness">互动咨询</router-link>
          </li>
        </ul>
        <el-form class="search">
          <el-input v-model="content" type="text" style="height:30px" @input="submit"
          placeholder="景点查询..." /> <!-- loginSwitch ? userName : '登录' -->
          <span @click="clickFn" ref="login"
          style="margin-left: 15px;width:80px;cursor: pointer;padding-top:5px">{{ userName || '登录' }}</span>
        </el-form>
      </div>
    </div>
  </div>
</template>
  
<script>
export default {
  data() {
    return {
      userName: '',
      userId: '',
      user: {},
      loginSwitch: false,
      content:''
    }
  },
  methods: {
    clickFn() {
      console.log('login--ref:', this.loginSwitch);
      // if(this.$refs.login)
      if(!this.loginSwitch) {
        this.$router.push('/login')
      } else {
        this.$router.push({path:'/userInfo', query: {userId: this.userId}})
      }
    },
    submit() {
      if(this.content.trim()) {
        console.log(this.content);
        this.$router.push({name:'search',params:{name:this.content}})
      }
      
    },
    // 页面单独刷新一次
    refresh() {
      this.$router.replace({path: this.$route.path})
    }
  },
  created() {
    let user = this.$store.state.userInfo
    console.log('vuex:user', user);
    console.log('user_name', user.user_name === '' || user.user_name === undefined);
    if(user.user_name === '' || user.user_name === undefined) {
      this.loginSwitch = false
    } else {
      this.loginSwitch = true
      this.userName = user.user_name
      this.userId = user.user_id
      this.refresh()
    }
  },
  mounted () {
  //  vuex
    
  },
};
</script>
  
  <style lang="scss" scoped>
#head {
  height: 190px;
  background-color: #61a8aa;
}
#head > div {
  display: flex;
  flex-direction: column;
}
#head > div > div:first-child {
  padding-left: 80px;
  padding-top: 50px;
  color: white;
}
#head > div > div:first-child h3 {
  margin-top: 15px;
}
#head > div > .nav {
  display: flex;
  position: relative;
}
#head > div > .nav ul {
  position: absolute;
  left: 300px;
  height: 60px;
  display: flex;
}
#head > div > .nav ul li {
  font-size: 18px;
  margin-right: 40px;
  
}
#head > div > .nav ul li > a {
  font-family: 微软雅黑;
  color: white;
}
#head > div > .nav > .search {
  // margin-top: 100px;
  position: absolute;
  right: 150px;
  bottom: -20px;
  color: white;
  display: flex;
  width: 200px;
}

#head > div > .nav > div a {
  font-size: 18px;
  color: white;
}
</style>